package com.gw.detail.controllor.detail;

import com.gw.detail.domain.Rettung;
import com.gw.detail.service.IRettungService;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 救援连Controller
 *
 * @author WangBin
 * @date 2021-04-30
 */
@RestController
@RequestMapping("/detail/rettung")
public class RettungController extends BaseController {
    @Autowired
    private IRettungService rettungService;

    /**
     * 查询救援连列表
     */
    @PreAuthorize("@ss.hasPermi('detail:rettung:list')")
    @GetMapping("/list")
    public TableDataInfo list(Rettung rettung) {
        startPage();
        List<Rettung> list = rettungService.selectRettungList(rettung);
        return getDataTable(list);
    }

    /**
     * 导出救援连列表
     */
    @PreAuthorize("@ss.hasPermi('detail:rettung:export')")
    @Log(title = "救援连", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(Rettung rettung) {
        List<Rettung> list = rettungService.selectRettungList(rettung);
        ExcelUtil<Rettung> util = new ExcelUtil<Rettung>(Rettung.class);
        return util.exportExcel(list, "救援连数据");
    }

    /**
     * 获取救援连详细信息
     */
    @PreAuthorize("@ss.hasPermi('detail:rettung:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return AjaxResult.success(rettungService.selectRettungById(id));
    }

    /**
     * 新增救援连
     */
    @PreAuthorize("@ss.hasPermi('detail:rettung:add')")
    @Log(title = "救援连", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Rettung rettung) {
        return toAjax(rettungService.insertRettung(rettung));
    }

    /**
     * 修改救援连
     */
    @PreAuthorize("@ss.hasPermi('detail:rettung:edit')")
    @Log(title = "救援连", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Rettung rettung) {
        return toAjax(rettungService.updateRettung(rettung));
    }

    /**
     * 删除救援连
     */
    @PreAuthorize("@ss.hasPermi('detail:rettung:remove')")
    @Log(title = "救援连", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(rettungService.deleteRettungByIds(ids));
    }
}
